home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / stdlib / putenv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-07  |  1.3 KB  |  63 lines

  1. /* 
  2.  * putenv.c --
  3.  *
  4.  *    Puts a string of the form `name=value' into the environment.
  5.  *
  6.  * Copyright 1991 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that this copyright
  10.  * notice appears in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header$";
  18. #endif /* not lint */
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23.  
  24.  
  25. /*
  26.  *----------------------------------------------------------------------
  27.  *
  28.  * putenv --
  29.  *
  30.  *    Puts a string of the form `name=value' into the environment.
  31.  *
  32.  * Results:
  33.  *    Returns 0 on success, otherwize returns -1.
  34.  *
  35.  * Side effects:
  36.  *    Changes environment.
  37.  *
  38.  *----------------------------------------------------------------------
  39.  */
  40.  
  41. int
  42. putenv(string)
  43.     char *string;
  44. {
  45.     char *name;
  46.     char *value;
  47.  
  48.     if ((name = malloc(strlen(string) + 1)) == NULL) {
  49.     return -1;
  50.     }
  51.     strcpy(name, string);
  52.     if ((value = strchr(name, '=')) == NULL) {
  53.     free(name);
  54.     return -1;
  55.     }
  56.     *value = '\0';
  57.     ++value;
  58.     setenv(name, value);
  59.     free(name);
  60.     return 0;
  61. }
  62.  
  63.